var express = require('express');
var router = express.Router();
var async = require('async');
var userController = require('../controllers/acl_user');
var roleController = require('../controllers/acl_role');
var resourceController = require('../controllers/acl_resource');



router.post('/getMenu', function(req, res) {
    //获取前端传递过来的用户id
    let userId = req.body.id;
    try {
        async.auto({
            //通过用户id查询角色id
            getRoleId: function(cb) {
                global.acl.userRoles(userId, cb); //获取用户的角色id
            },
            //通过角色id查询角色详情
            getRole: ['getRoleId', function(data, cb) {
                let jsonRoleid = {};
                jsonRoleid.id = data.getRoleId[0];
                roleController.getOne(jsonRoleid, cb);
            }],
            //通过角色id查询权限列表【简单列表】
            getResource: ['getRoleId', function(data, cb) {
                global.acl.whatResources(data.getRoleId[0], cb)
            }]
        }, function(err, data) {
            res.send({
                code: "200",
                msg: "获取详情成功",
                roleInfo: data.getRole,
                resources: data.getResource
            });
        });
    } catch (err) {
        res.end(err.stack);
    }
});


module.exports = router;